package com.forcast;

import com.VO.bihuaVO;
import com.VO.zhugeVO;
import com.jdbc.dbcon;
import com.jdbc.dao.bihuaDao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class ZhuGeNum {
	private zhugeVO q = null;
	private dbcon conn = null;
	private Connection c =null;
	private Statement st = null;
	private String sqlstr = null;
	private bihuaDao bhDao = null;
	
	public zhugeVO getVObyid(int id){
		q = new zhugeVO();
		q.setId(id);
		conn = new dbcon();
		c = conn.getConnection();
		sqlstr = "select  * for zhugenum where id = ?";
		try{
		st = c.createStatement();
		ResultSet rs = st.executeQuery(sqlstr);
		while (rs.next()){
			q.setQno(rs.getString("qno"));
			q.setQdetail(rs.getString("qdetail"));
			q.setQexplain(rs.getString("qexplain"));
		}
		c.close();
		return q;		
		}catch(Exception e){
			System.out.println("查询失败："+e.getMessage());
		}
		return null;
	}
	
	public zhugeVO getQbyNum(String num){
		return null;
		
	}
	public zhugeVO getQbyWords(String words){
		bhDao = new bihuaDao();
		if ((words=="")||words==null){
			System.out.println("words that server get is null");
			return null;
		}else{
			String w[] = words.split("");
			ArrayList<bihuaVO> list = new ArrayList<bihuaVO>();
			String strn="";
			for(int i=1;i<w.length;i++){
				list.add(new bihuaVO(w[i]));
				System.out.println(list.get(i-1).toString());
				int t = Integer.parseInt(list.get(i-1).getBh());
				t=t%10;
				strn = strn + Integer.toString(t);
			}
			int qid = Integer.parseInt(strn);
			qid = (qid%384==0)?384:qid%384;
			zhugeVO zVO = new zhugeVO(qid);
			System.out.println(strn);
			return zVO;
		}
		
		
	}
	public static void main (String arg[]){
		String words = "佑咱统";
		String w[]=words.split("");
		for(int i=1;i<w.length;i++){
			System.out.println("w["+i+"]: "+w[i]);
		}
		ZhuGeNum z = new ZhuGeNum();
		z.getQbyWords(words);
		
//		ArrayList<bihuaVO> list = new ArrayList<bihuaVO>();
//		for(int i=1;i<w.length;i++){
//			list.add(new bihuaVO(w[i]));
//		}
//		System.out.println(w.length);
		 
	}
}
